Ext.define("byb.view.TopView", {
    extend: "Ext.panel.Panel",
    alias: "widget.TopView",
    border: false,
    cls: "topview",
    baseCls : "ex-panel",
    layout:  'fit',
    items:[{
    	xtype:"container",
        baseCls : "ex-panel",
        style:"text-align:right;color:white",
    	cls:"logo",
    	layout: {
    	    type: 'hbox',
    	    pack: 'end',
    	    align: 'middle'
    	},
        height: 78,
    	items: [{
    	    xtype: "container",
    	    layout: 'hbox',
    	    items:[{
                xtype: "container",
                id: "gaojingwindow",
                show: 1,
                width: 400,
                height: 70,
                style: 'overflow:auto;text-align:left;background:#ffffdb;padding:0 10px;color:#333;border-radius:10px;border:1px solid #a5c3e0',
                listeners: {
                    afterrender: function(ctx) {
                    }
                }
            }]
    	} ,{
    		xtype:"container",
            baseCls : "ex-panel",
    		height: 78,
            width: 260,
    		layout: "vbox",
            style:"text-align:right;color:white;margin-right:20px;",
            items:[{
            	name:"loginfo",
                baseCls : "ex-panel",
                style: "margin-top:15px;",
        		height: 20,
                width: 260
            }, {
            	name:"orgDesc",
                baseCls : "ex-panel",
        		height: 35,
                width: 260
            }, {
            	xtype:"container",
                baseCls : "ex-panel",
        		height: 35,
                width: 260,
            	items:[{
    	            xtype:"combo",
    	            style:"float:right",
    	            fieldLabel:"公司",
    	            displayField:"name",
    	            valueField:"id",
    	            store:Ext.create("byb.store.system.Company"),
    	            name:"companyId",
    	            labelStyle:"text-align:right;color:white",
    	            labelWidth:50,
    	            allowBlank:true,
    	            editable: false,
    	            hidden : true,
    	            forceSelection: true,
    	            listeners: {
    	                afterrender: function(ctx, e,eOpts){
    	                    ctx.getStore().load();
    	                    ctx.getStore().on("load",function(store,records,successful,eOpts){
    	                    	if(records && records[0] && records[0].raw){
	    	                        var model= records[0];
	    	                        ctx.select(model);
    	                    	}
    	                    });
    	                    
    	                }
            			, change: function(ctx,newValue,oldValue,eOpts ){
            				byb.view.TopView.switchCompany(ctx,newValue,oldValue,eOpts);
    		        	}
    	            }
            	}]
        	}]
    	}]
    }]
    , initComponent: function() {
        this.callParent(arguments);
    }
	, statics : {
		switchCompany : function(ctx,newValue,oldValue,eOpts ){
			Ext.Ajax.request({
			    url: byb.Constant.APIRoot + '/login/switchCompany',
			    params: {
			        companyId : newValue 
			    },
			    success: function(response) {
                    var obj = Ext.decode(response.responseText);
                    if (obj && obj.hasOwnProperty("results")) {
                        byb.Constant.type = obj.results;
                        if (typeof mf == 'function') mf();
                    }
    				var data = Ext.ComponentQuery.query('AccordionView')[0].initButton;
    				var btn = null;
    				if(data) {
    					btn = data.button;
    				}
    				if(btn){
    					btn.fireEvent(byb.Constant.LeftMenuSelectedButton,data);
    				}
			    }
			});
		}
	}
});